// src/main/java/com/team5/websocket/NewsPushScheduler.java
package com.xykj.web.websocket;

import com.xykj.pojo.dto.NewsFlashDto;
import com.xykj.service.NewsFlashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NewsPushScheduler {

    @Autowired
    private NewsFlashService newsFlashService;

    @Autowired
    private NewsWebSocketHandler newsWebSocketHandler;

    private static final int PAGE_NUM  = 1;
    private static final int PAGE_SIZE = 10;

    @Scheduled(fixedRate = 10000)
    public void pushNewsFlashFromDb() {
        List<NewsFlashDto> list = newsFlashService.queryNewsFlash(PAGE_NUM, PAGE_SIZE);
        if (!list.isEmpty()) {
            newsWebSocketHandler.broadcast(list);
        }
    }

}
